home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / system-tools / tinymeter / source / tinymeter_main / volumes.c < prev   
Encoding:
C/C++ Source or Header  |  1996-03-21  |  4.7 KB  |  209 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <dos/dostags.h>
  6. #include <dos/notify.h>
  7. #include <string.h>
  8. #include <libraries/WBStart.h>
  9. #include <workbench/startup.h>
  10. #include <workbench/workbench.h>
  11. #include <intuition/classes.h>
  12. #include <clib/macros.h>
  13. #include "gaugeclass.h"
  14. #include "tinymeter.h"
  15. #include "launchclass.h"
  16.  
  17. getVolsize(struct tm_data *data,char *volname)
  18. {
  19.     struct InfoData  inf;
  20.     struct DevProc  *devproc;
  21.     if(devproc=(struct DevProc *)GetDeviceProc(volname,NULL))
  22.     {
  23.     if( DoPkt(devproc->dvp_Port,ACTION_DISK_INFO,MKBADDR(&inf),NULL,NULL,NULL,NULL)==DOSTRUE)
  24.     {
  25.         switch(inf.id_DiskType)
  26.         {
  27.         case    0x42555359:
  28.             data->volmax=0;
  29.             data->volcur=GAU_err_busy;
  30.             break;
  31.         case    ID_UNREADABLE_DISK:
  32.             data->volmax=0;
  33.             data->volcur=GAU_err_unreadable;
  34.             break;
  35.         case    ID_NOT_REALLY_DOS:
  36.             data->volmax=0;
  37.             data->volcur=GAU_err_nodos;
  38.             break;
  39.         case    ID_NO_DISK_PRESENT:
  40.             data->volmax=0;
  41.             data->volcur=GAU_err_notpresent;
  42.             break;
  43.         case    ID_KICKSTART_DISK:
  44.             data->volmax=0L;
  45.             data->volcur=GAU_err_kickstart;
  46.             break;
  47.         default:
  48.             data->volcur=(inf.id_NumBlocks-inf.id_NumBlocksUsed)*inf.id_BytesPerBlock;
  49.             data->volmax=inf.id_NumBlocks*inf.id_BytesPerBlock;
  50.             data->voltype=inf.id_DiskType;
  51.             break;
  52.         }
  53.     }
  54.     FreeDeviceProc(devproc);
  55.     }
  56.     else
  57.     {
  58.     data->volmax=0;
  59.     data->volcur=GAU_err_notmount;
  60.     }
  61. }
  62.  
  63. BOOL CopyPathList(struct PathList **pla, struct PathList **plc,struct PathList *oldpl)
  64. {
  65.     struct PathList *pl1=oldpl,*pl2=*plc,*pl3=NULL;
  66.     while (pl1)
  67.     {
  68.     if (!(pl3 || (pl3=(struct PathList *)AllocVec(sizeof(struct PathList),MEMF_PUBLIC|MEMF_CLEAR)))) return(FALSE);
  69.     if (pl3->PathLock=DupLock(pl1->PathLock))
  70.     {
  71.         if (*pla) pl2->NextPath=MKBADDR(pl3);
  72.         else *pla=pl3;
  73.         pl2=pl3;
  74.         pl3=NULL;
  75.     }
  76.     pl1=BADDR(pl1->NextPath);
  77.     }
  78.     if (pl3) FreeVec(pl3);
  79.     *plc=pl2;
  80.     return(TRUE);
  81. }
  82.  
  83. void FreePathList(struct PathList *pla)
  84. {
  85.     if (pla)
  86.     {
  87.     struct PathList *pl1=pla,*pl2;
  88.     do
  89.     {
  90.         pl2=BADDR(pl1->NextPath);
  91.         UnLock(pl1->PathLock);
  92.         FreeVec(pl1);
  93.     }
  94.     while (pl1=pl2);
  95.     }
  96. }
  97.  
  98. BOOL InitWorkbenchPath(struct tm_data *data)
  99. {
  100.     struct Process *wbproc=(struct Process *)FindTask("Workbench");
  101.     if(!wbproc)     wbproc=(struct Process *)FindTask("DirectoryOpus");
  102.  
  103.     if (wbproc && (wbproc->pr_Task.tc_Node.ln_Type==NT_PROCESS))
  104.     {
  105.     struct CommandLineInterface *wbcli=BADDR(wbproc->pr_CLI);
  106.     if (wbcli)
  107.     {
  108.         struct PathList *dummy;
  109.         if (CopyPathList(&data->GlobalPath,&dummy,(struct PathList *) BADDR(wbcli->cli_CommandDir)));
  110.     }
  111.     }
  112.     return(TRUE); 
  113. }
  114.  
  115. FreeWorkbenchPath(struct tm_data *data)
  116. {
  117.     FreePathList(data->GlobalPath);
  118. }
  119.  
  120. RunCLI(struct lau_entry *entry, struct tm_data *data)
  121. {
  122.     BOOL            rc=TRUE;
  123.     char            *def =0;
  124.     BPTR            newcd,
  125.             ofh,
  126.             oldcd,
  127.             ifh;
  128.     struct MsgPort  *newct=NULL;
  129.  
  130.     if(entry->lau_pth)  newcd=Lock(entry->lau_pth,SHARED_LOCK);
  131.     else                newcd=0L;
  132.     if(!newcd)
  133.     {
  134.     char *foo;
  135.     int i;
  136.     foo=(char *)FilePart(entry->lau_cmd);
  137.     if(def=(char *)AllocVec(foo-entry->lau_cmd+2,0L))
  138.     {
  139.         for(i=0;i<(foo-entry->lau_cmd);i++) def[i]=entry->lau_cmd[i];
  140.         def[i]=0;
  141.         newcd=Lock(def,SHARED_LOCK);
  142.     }
  143.     }
  144.     if(!(ofh=Open(entry->lau_out, MODE_NEWFILE)))
  145.      ofh=Open("NIL:",         MODE_NEWFILE);
  146.     if(ofh)
  147.     {
  148.     if (IsInteractive(ofh))
  149.     {
  150.         struct MsgPort *oldct;
  151.         newct=((struct FileHandle *) BADDR(ofh))->fh_Type;
  152.         oldct=(struct MsgPort *)SetConsoleTask(newct);
  153.         ifh=Open("CONSOLE:",MODE_OLDFILE);
  154.         SetConsoleTask(oldct);
  155.     }
  156.     else ifh=Open("NIL:",MODE_OLDFILE);
  157.     if (ifh)
  158.     {
  159.         struct PathList *pla=NULL,*plc=NULL;
  160.         oldcd=CurrentDir(newcd);
  161.         if(CopyPathList(&pla,&plc,data->GlobalPath))
  162.         {
  163.         if (SystemTags(entry->lau_cmd,
  164.             SYS_Output,     ofh,
  165.             SYS_Input,      ifh,
  166.             SYS_Asynch,     TRUE, 
  167.             SYS_UserShell,  TRUE,
  168.             NP_StackSize,   entry->lau_stack < 4096L ? 4096L : entry->lau_stack,
  169.             NP_Priority,    0,
  170.             NP_Path,        MKBADDR(pla),
  171.             NP_ConsoleTask, newct,
  172.             TAG_DONE)!=-1) rc=FALSE;
  173.         CurrentDir(oldcd);
  174.         if(rc)
  175.         {
  176.             Close(ifh);
  177.             FreePathList(pla);
  178.         }
  179.         }
  180.     }
  181.     if(rc)
  182.     {
  183.         Close(ofh);
  184.         DisplayBeep(0);
  185.     }
  186.     }
  187.     if(def)FreeVec(def);
  188.     UnLock(newcd);
  189. }
  190.  
  191. RunWB(struct lau_entry *entry, struct tm_data *data)
  192. {
  193.     if(WBStartTags(WBStart_Name,            entry->lau_cmd,
  194.            WBStart_DirectoryName,   entry->lau_pth,
  195.            WBStart_Stack,           entry->lau_stack < 4096L ? 4096L : entry->lau_stack,
  196.            TAG_END))
  197.     {
  198.     DisplayBeep(0);
  199.     }
  200. }
  201.  
  202. int RunFile(struct lau_entry *entry, struct tm_data *data)
  203. {
  204.     if(entry->lau_type==0) RunWB(entry,data);
  205.     else                   RunCLI(entry,data);
  206. }
  207.  
  208.  
  209.